package com.xzx.youku;

import android.view.View;
import android.view.animation.RotateAnimation;

/**
 * @author xinzhixuan
 * @version V1.0
 * @date 2017/5/16 23:24
 * 控制视图的显示与隐藏
 */
public class Tools {

    /**
     * 隐藏视图
     * @param view
     */
    public static void hideView(View view) {
        hideView(view, 0);
    }

    /**
     * 显示视图
     * @param view
     */
    public static void showView(View view) {
        showView(view, 0);
    }

    /**
     * 隐藏视图
     * @param view
     * @param startOffset 动画延迟开始时间
     */
    public static void hideView(View view, int startOffset) {
        RotateAnimation rotateAnimation = new RotateAnimation(0, 180, RotateAnimation.RELATIVE_TO_SELF, 0.5f,
                                                              RotateAnimation.RELATIVE_TO_SELF, 1f);
        rotateAnimation.setDuration(500);
        rotateAnimation.setFillAfter(true);//旋转后定在那里
        rotateAnimation.setStartOffset(startOffset);
        view.startAnimation(rotateAnimation);
    }

    public static void showView(View view, int startOffset) {
        RotateAnimation rotateAnimation = new RotateAnimation(180, 360, RotateAnimation.RELATIVE_TO_SELF, 0.5f,
                                                              RotateAnimation.RELATIVE_TO_SELF, 1f);
        rotateAnimation.setDuration(500);
        rotateAnimation.setFillAfter(true);//旋转后定在那里
        rotateAnimation.setStartOffset(startOffset);
        view.startAnimation(rotateAnimation);
    }
}
